package com.example.hello;

import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.GridView;
import android.widget.SimpleAdapter;

public class ShowUserActivity extends Activity {
	
	private GridView gv_allUser;
	private DBHelper db = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show_user);
		
		db = new DBHelper(this);
		
		gv_allUser = (GridView)findViewById(R.id.gv_allUser);
		List<Map<String,Object>> returnList = db.findAll();
		SimpleAdapter adapter = new SimpleAdapter(this, returnList, R.layout.grid_items, new String[]{"img","loginName"}, new int[]{R.id.ItemImage, R.id.ItemText});
		gv_allUser.setAdapter(adapter);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.show_user, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		db.closeDBRes();
	}

}
